<template>
  <div class="ts-register" ref="fullScreen">
    <ts-header title="注册" back></ts-header>
    <form-input :formData="formData"
                btnText="下一步"
                :codeSeconds="codeSeconds"
                :codeInterval="codeInterval"
                mode="register"
                @submit="next()"></form-input>
  </div>
</template>

<script>
  import FormInput from '../../components/module/FormInput.vue'
  import {REGISTER} from '../../assets/js/api'
  import {SET_REGISTER} from '../../store/mutations-types'

  export default {
    components: {FormInput},
    name: 'register',
    data() {
      return {
        formData: {
          type: 1,
          tel: '',
          code: null,
          password: '',
          rePassword: '',
        },
        codeSeconds: 60,
        codeInterval: null
      }
    },
    methods: {
      async next() {
        let json = await this.$http.post(REGISTER, this.formData, {show: true});
        if (json.result === 1) {
          let {tel, type} = this.formData;
          //保存当前手机，步骤,token
          let token = json.data.token;
          let member_id = json.member_id;
          this.$store.commit(SET_REGISTER, {tel, type, token, member_id});
          let toast = this.$toast({message: '注册成功，跳转中...', position: 'middle'});
          setTimeout(() => {
            toast.close();
            this.$router.replace({path: '/register/addProfile'});
          }, 2000)
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  @import "../../assets/css/variables";
  @import "../../assets/css/mixin";

  .ts-register {
    height: 100%;
    background-color: #ffffff;
  }
</style>
